package com.dongjiantong.sys.serviceImpl;

import com.alibaba.dubbo.config.annotation.Service;
import com.dongjiantong.mybatis.ServiceMybatis;
import com.dongjiantong.sys.enums.LogsEnum;
import com.dongjiantong.sys.mapper.SysLogsMapper;
import com.dongjiantong.sys.model.SysLogs;
import com.dongjiantong.sys.service.SysLogsService;
import lombok.extern.slf4j.Slf4j;

import javax.annotation.Resource;
import java.util.Date;

/**
 * @author cao
 * @create 2017-11-23 下午3:16
 **/

@Slf4j
@Service(version = "1.0.0")
public class SysLogsServiceImpl extends ServiceMybatis<SysLogs> implements SysLogsService {
    @Resource
    private SysLogsMapper sysLogsMapper;

//    @Override
//    public void createLogs(SysLogs sysLogs)
//    {
//        sysLogs.setCreatedAt(new Date());
//        sysLogsMapper.insert(sysLogs);
//    }

    @Override
    public void createLogs(LogsEnum logsEnum,String table,String objId,String before,String after,Long userId)
    {
        createLogs(logsEnum,  table,  objId, "", "",  before,  after,  userId);
    }

    @Override
    public void createLogs(LogsEnum logsEnum, String table, String objId, String title, String content, String before, String after, Long userId)
    {
        if(title==null)
        {
            title="";
        }
        if(content==null)
        {
            content="";
        }

        SysLogs sysLogs = new SysLogs();

        sysLogs.setLogtype(logsEnum.getCode());
        sysLogs.setTitle(title==""?logsEnum.getName():title);
        sysLogs.setContent(content==""?logsEnum.getName():title);
        sysLogs.setBefore(before);
        sysLogs.setAfter(after);
        sysLogs.setObjtable(table);
        sysLogs.setObjid(objId);
        sysLogs.setCreatedId(userId);
        sysLogs.setCreatedAt(new Date());

        sysLogsMapper.insert(sysLogs);

    }
}
